/**
 * Copyright (c) 2021-2024 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

<%= Common::include_plugin_files "compiler_extensions", "header_path_implementation_codegen" %>

inline void CreateLoadObjectDynamic([[maybe_unused]] Inst *inst)
{
% Common::each_plugin_suboption("compiler_extensions", "load_object_dynamic_codegen") do |load_object_dynamic_codegen|
    if (<%= load_object_dynamic_codegen %>(inst)) {
        return;
    }
% end

    LOG(WARNING, COMPILER) << "Cannot encode LoadObjectDynamic";
    GetEncoder()->SetFalseResult();
}

inline void CreateStoreObjectDynamic([[maybe_unused]] Inst *inst)
{
% Common::each_plugin_suboption("compiler_extensions", "store_object_dynamic_codegen") do |store_object_dynamic_codegen|
    if (<%= store_object_dynamic_codegen %>(inst)) {
        return;
    }
% end

    LOG(WARNING, COMPILER) << "Cannot encode StoreObjectDynamic";
    GetEncoder()->SetFalseResult();
}

inline void ResolveCallByName([[maybe_unused]] ResolveVirtualInst *inst)
{
% Common::each_plugin_suboption("compiler_extensions", "resolve_call_by_name") do |resolve_call_by_name|
    if (<%= resolve_call_by_name %>(inst)) {
        return;
    }
% end

    LOG(WARNING, COMPILER) << "Cannot encode ResolveCallByName";
    GetEncoder()->SetFalseResult();
}

inline void GetNativeMethod([[maybe_unused]] IntrinsicInst *inst, [[maybe_unused]] Reg dst, [[maybe_unused]] SRCREGS src)
{
    [[maybe_unused]] auto *graph = inst->GetBasicBlock()->GetGraph();
% Common::each_plugin_suboption("compiler_extensions", "get_native_method_codegen") do |get_native_method_codegen, plugin_lang|
    if (graph->GetLanguage() == SourceLanguage::<%= plugin_lang %>) {
        <%= get_native_method_codegen %>(inst, dst, src);
        return;
    }
% end
    LOG(WARNING, COMPILER) << "Cannot encode intrinsic GetNativeMethod";
    GetEncoder()->SetFalseResult();
}

inline void GetNativeMethodManagedClass([[maybe_unused]] IntrinsicInst *inst, [[maybe_unused]] Reg dst, [[maybe_unused]] SRCREGS src)
{
    [[maybe_unused]] auto *graph = inst->GetBasicBlock()->GetGraph();
% Common::each_plugin_suboption("compiler_extensions", "get_native_method_managed_class_codegen") do |get_native_method_managed_class_codegen, plugin_lang|
    if (graph->GetLanguage() == SourceLanguage::<%= plugin_lang %>) {
        <%= get_native_method_managed_class_codegen %>(inst, dst, src);
        return;
    }
% end
    LOG(WARNING, COMPILER) << "Cannot encode intrinsic GetNativeMethodManagedClass";
    GetEncoder()->SetFalseResult();
}

inline void GetMethodNativePointer([[maybe_unused]] IntrinsicInst *inst, [[maybe_unused]] Reg dst, [[maybe_unused]] SRCREGS src)
{
    [[maybe_unused]] auto *graph = inst->GetBasicBlock()->GetGraph();
% Common::each_plugin_suboption("compiler_extensions", "get_method_native_pointer_codegen") do |get_method_native_pointer_codegen, plugin_lang|
    if (graph->GetLanguage() == SourceLanguage::<%= plugin_lang %>) {
        <%= get_method_native_pointer_codegen %>(inst, dst, src);
        return;
    }
% end
    LOG(WARNING, COMPILER) << "Cannot encode intrinsic GetMethodNativePointer";
    GetEncoder()->SetFalseResult();
}

inline void GetNativeApiEnv([[maybe_unused]] IntrinsicInst *inst, [[maybe_unused]] Reg dst, [[maybe_unused]] SRCREGS src)
{
    [[maybe_unused]] auto *graph = inst->GetBasicBlock()->GetGraph();
% Common::each_plugin_suboption("compiler_extensions", "get_native_api_env_codegen") do |get_native_api_env_codegen, plugin_lang|
    if (graph->GetLanguage() == SourceLanguage::<%= plugin_lang %>) {
        <%= get_native_api_env_codegen %>(inst, dst, src);
        return;
    }
% end
    LOG(WARNING, COMPILER) << "Cannot encode intrinsic GetNativeApiEnv";
    GetEncoder()->SetFalseResult();
}

inline void BeginNativeMethod([[maybe_unused]] IntrinsicInst *inst, [[maybe_unused]] Reg dst, [[maybe_unused]] SRCREGS src)
{
    [[maybe_unused]] auto *graph = inst->GetBasicBlock()->GetGraph();
% Common::each_plugin_suboption("compiler_extensions", "begin_native_method_codegen") do |begin_native_method_codegen, plugin_lang|
    if (graph->GetLanguage() == SourceLanguage::<%= plugin_lang %>) {
        <%= begin_native_method_codegen %>(inst, dst, src);
        return;
    }
% end
    LOG(WARNING, COMPILER) << "Cannot encode intrinsic BeginNativeMethod";
    GetEncoder()->SetFalseResult();
}

inline void EndNativeMethodPrim([[maybe_unused]] IntrinsicInst *inst, [[maybe_unused]] Reg dst, [[maybe_unused]] SRCREGS src)
{
    [[maybe_unused]] auto *graph = inst->GetBasicBlock()->GetGraph();
% Common::each_plugin_suboption("compiler_extensions", "end_native_method_prim_codegen") do |end_native_method_prim_codegen, plugin_lang|
    if (graph->GetLanguage() == SourceLanguage::<%= plugin_lang %>) {
        <%= end_native_method_prim_codegen %>(inst, dst, src);
        return;
    }
% end
    LOG(WARNING, COMPILER) << "Cannot encode intrinsic EndNativeMethodPrim";
    GetEncoder()->SetFalseResult();
}

inline void EndNativeMethodObj([[maybe_unused]] IntrinsicInst *inst, [[maybe_unused]] Reg dst, [[maybe_unused]] SRCREGS src)
{
    [[maybe_unused]] auto *graph = inst->GetBasicBlock()->GetGraph();
% Common::each_plugin_suboption("compiler_extensions", "end_native_method_obj_codegen") do |end_native_method_obj_codegen, plugin_lang|
    if (graph->GetLanguage() == SourceLanguage::<%= plugin_lang %>) {
        <%= end_native_method_obj_codegen %>(inst, dst, src);
        return;
    }
% end
    LOG(WARNING, COMPILER) << "Cannot encode intrinsic EndNativeMethodObj";
    GetEncoder()->SetFalseResult();
}

inline void CheckNativeException([[maybe_unused]] IntrinsicInst *inst, [[maybe_unused]] Reg dst, [[maybe_unused]] SRCREGS src)
{
    [[maybe_unused]] auto *graph = inst->GetBasicBlock()->GetGraph();
% Common::each_plugin_suboption("compiler_extensions", "check_native_exception_codegen") do |check_native_exception_codegen, plugin_lang|
    if (graph->GetLanguage() == SourceLanguage::<%= plugin_lang %>) {
        <%= check_native_exception_codegen %>(inst, dst, src);
        return;
    }
% end
    LOG(WARNING, COMPILER) << "Cannot encode intrinsic CheckNativeException";
    GetEncoder()->SetFalseResult();
}

inline void WrapObjectNative([[maybe_unused]] WrapObjectNativeInst *inst)
{
    [[maybe_unused]] auto *graph = inst->GetBasicBlock()->GetGraph();
% Common::each_plugin_suboption("compiler_extensions", "wrap_object_native_codegen") do |wrap_object_native_codegen, plugin_lang|
    if (graph->GetLanguage() == SourceLanguage::<%= plugin_lang %>) {
        <%= wrap_object_native_codegen %>(inst);
        return;
    }
% end
    LOG(WARNING, COMPILER) << "Cannot encode WrapObjectNative";
    GetEncoder()->SetFalseResult();
}
